<template>

  <a-spin :spinning="confirmLoading">
    <a-form :form="form">

      <a-row>

        <!-- 表单数据 -->
<!--        <AssetFixedInfo ref="assetFixedInfo"></AssetFixedInfo>-->

<!--        <a-col :span="24">-->
<!--          <a-form-item label="报废原因" :labelCol="labelCol2" :wrapperCol="wrapperCol2">-->
<!--            <a-textarea v-if="!disabled" v-decorator="['reason', validatorRules.reason]"-->
<!--                        rows="4" placeholder="请输入报废原因" />-->
<!--            <span v-else>{{ data.reason }}</span>-->
<!--          </a-form-item>-->
<!--        </a-col>-->

        <a-col :span="24" style="margin-top: 15px">
          <a-form-item label="标题" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
            <a-input v-if="!disabled" v-decorator="['title', validatorRules.title]" rows="4" placeholder="请输入标题" />
            <span v-else>{{ data.title }}</span>
          </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item label="申请说明" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
            <a-textarea v-if="!disabled" v-decorator="['processDescription', validatorRules.processDescription]"
                        rows="4" placeholder="请输入申请说明" />
            <span v-else>{{ data.processDescription }}</span>
          </a-form-item>
        </a-col>

      </a-row>

    </a-form>

    <BaseForm v-if="!disabled" ref="baseForma"></BaseForm>

    <a-form-item v-if="!disabled"
                 :wrapperCol="{ span: 24 }"
                 style="text-align: center">
      <a-button type="primary" :disabled="disabled || btndisabled" @click="handleSubmit">保存</a-button>
      <a-button style="margin-left: 8px" :disabled="disabled" @click="close">取消</a-button>
    </a-form-item>

    <a-form-item v-if="task"
                 :wrapperCol="{ span: 24 }"
                 style="text-align: center">
      <a-button type="primary" @click="passTask">通过</a-button>
      <a-button style="margin-left: 8px" @click="backTask">驳回</a-button>
    </a-form-item>
  </a-spin>
</template>

<script>

import pick from 'lodash.pick'
import '@/assets/less/TableExpand.less'
import JDate from '@/components/jeecg/JDate'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import { ActivitiFormMixin } from '@/views/activiti/mixins/activitiFormMixin'
import BaseForm from './BaseForm'
import { VALIDATE_NO_PASSED, validateFormAndTables } from '@/utils/JEditableTableUtil'
import { httpAction } from '@api/manage'
// import AssetFixedInfo from './AssetFixedInfo'

export default {
  name: 'AssetFixedScrap',
  mixins: [ActivitiFormMixin],
  components: {
    BaseForm,
    // AssetFixedInfo,
    JDate,
    JDictSelectTag,
    JSearchSelectTag
  },
  data () {
    return {
      // form
      form: this.$form.createForm(this),
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 }
      },
      validatorRules: {
        title: {
          rules: [
            { required: true, message: '请输入标题!' }
          ]
        },
        processDescription: {
          rules: [
            { required: true, message: '请输入申请说明!' }
          ]
        },
        reason: {
          rules: [
            { required: true, message: '请输入维修事项!' }
          ]
        }
      }
    }
  },
  created () {
    this.init()
  },
  methods: {
    setValue () {
      // this.$refs.assetFixedInfo.disableSubmit = this.disabled
      // this.$refs.assetFixedInfo.showModal(this.data.dataMap)
      this.data.title = this.processData.title
      if (!this.disabled) {
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.data, 'processDescription', 'title'))
          if (this.processData.procDefId) {
            let keys = []
            keys.push(this.processData.procDefId)
            this.$refs.baseForma.selectedRowKeys = keys
          }
          this.$refs.baseForma.queryParam = { status: 1, routeName: this.processData.routeName }
          this.$refs.baseForma.loadData(1)
        })
      }
    },
    // handler
    handleSubmit (e) {
      let that =this
      this.form.validateFields((err, values) => {
        if (!err) {
          if (this.$refs.baseForma.selectedRowKeys.length != 1) {
            this.$message.warning('请选择流程图')
            return
          }
          let formData = values
          formData.data = this.data.dataMap
          formData.oldData = this.oldDataMap
          formData.procDefId = this.$refs.baseForma.selectedRowKeys[0]
          that.handleSubmitVa(formData)

          // this.confirmLoading = true
          //
          // let param ={
          //   id:this.data.dataMap.id,
          //   assetFixedCategoryId:values.assetFixedCategoryId,
          //   reason: values.reason,
          //   type:'4'
          // }
          // httpAction('/zcgl/assetFixed/createLog', param, 'POST').then((res) => {
          //   if (res.success) {
          //     let formData = values
          //     formData.data = this.data.dataMap
          //     formData.oldData = this.oldDataMap
          //     formData.procDefId = this.$refs.baseForma.selectedRowKeys[0]
          //     that.handleSubmitVa(formData)
          //   } else {
          //     this.$message.warning(res.message)
          //   }
          // }).finally(() => {
          //   this.confirmLoading = false
          // })
        }
      })
    }
  }
}
</script>

<!--lang="less"-->
<style lang="less" scoped>
@import '~@assets/less/common.less';

.ant-form-item {
  margin-bottom: 10px;
}

.ant-col {
  min-height: 51px !important;
}

/*.ant-form-item span {*/
/*  position: absolute !important;*/
/*  min-height: 20px !important;*/
/*}*/
</style>